package com.gfm.story.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * @BelongsProject: story
 * @BelongsPackage: com.gfm.story.util
 * @Author: Administrator
 * @CreateTime: 2019-06-11 11:37
 * @Description: ${Description}
 */
public class ReadTxtFile {

    public String readTxtFile(String filePath){
        try {
            String encoding="UTF-8";
            File file=new File(filePath);
            if(file.isFile() && file.exists()){ //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file),encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while((lineTxt = bufferedReader.readLine()) != null){

                    return lineTxt.replaceAll("。", "。</br>");//返回解析内容
                }
                read.close();
            }else{
                return "找不到指定的文件".concat("</br>");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "读取文件内容出错".concat("</br>");
        }
        return null;
    }
}
